package vip.zhenzicheng.design_patterns.flyweight;

import java.util.HashMap;

/**
 * 单例工厂 带有缓存区
 *
 * @author zhenzicheng
 * @date 2022-05-26 18:09
 */
public class BoxFactory {

  private static final BoxFactory SINGLETON = new BoxFactory();
  private final HashMap<String, AbstractBox> cacheMap;

  private BoxFactory() {
    cacheMap = new HashMap<>(4);
    cacheMap.put("I", new IBox());
    cacheMap.put("L", new LBox());
    cacheMap.put("O", new OBox());
  }

  // 提供一个方法获取该工厂类对象
  public static BoxFactory getInstance() {
    return SINGLETON;
  }

  // 根据名称获取图形对象
  public AbstractBox getShape(String name) {
    return cacheMap.get(name);
  }
}
